package sdk.webview.fmc.com.fmcsdk.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


public class DBHelper extends SQLiteOpenHelper {

    // 版本号

    public static final int DBVERSION =5;

    private static final String DB_NAME = "fmc.db";


    public DBHelper(Context context) {
        super(context, DB_NAME, null, DBVERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        // 创建H5图片表
        db.execSQL(IMAGE.CREATE_SQL);
        db.execSQL(VIDEO.CREATE_SQL);
        db.execSQL(ActivityJson.CREATE_SQL);

        db.execSQL(InspectPic.CREATE_SQL);
        db.execSQL(InspectPoint.CREATE_SQL);
        db.execSQL(InspectState.CREATE_SQL);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        switch (oldVersion) {
            case 1:
                db.execSQL("alter table h5_image add timeStamp text");//如果老版本是1的用户，数据表新加入timeStamp字段
                break;
            case 2:
                db.execSQL(VIDEO.CREATE_SQL);
//                onCreate(db);
                break;
//            case 3:
//                db.execSQL(VIDEO.CREATE_SQL);
//                onCreate(db);
//                break;
        }

        if (oldVersion < 5){
            db.execSQL(ActivityJson.CREATE_SQL);

            db.execSQL(InspectPic.CREATE_SQL);
            db.execSQL(InspectPoint.CREATE_SQL);
            db.execSQL(InspectState.CREATE_SQL);
        }
    }
}